﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Soundteller.Audio.Model;
using Soundteller.Audio.Repositories;
using Soundteller.Audio.Repositories.Interfaces;
using Soundteller.Common.Tests;
using Moq;
using Soundteller.Audio.Model.Interfaces;
using System.Collections.Generic;

namespace Soundteller.Audio.Tests.Unit.Repositories.SongRepositorySpecifications
{
    public abstract class WhenGet : TestBase
    {
        protected ISongRepository SongRepository { get; private set; }
        protected Mock<IMemoryContext> Context { get; private set; }
        protected List<Song> SongsInRepository { get; set; }
        protected abstract Guid SongId { get; }
        protected Song Result { get; private set; }

        protected override void Arrange()
        {
            SongsInRepository = new List<Song>();
            Context = new Mock<IMemoryContext>();
            Context.Setup(c => c.Songs).Returns(SongsInRepository);

            SongRepository = new SongRepository(Context.Object);
        }

        protected override void Act()
        {
            Result = SongRepository.GetById(SongId);
        }
    }

    [TestClass]
    public class WhenGetGivenUnknownId : WhenGet
    {
        protected override Guid SongId
        {
            get { return Guid.NewGuid(); }
        }

        [TestMethod]
        public void ThenResultShouldBeEmpty()
        {
            Assert.IsNull(Result);
        }
    }

    [TestClass]
    public class WhenGetGivenKnownId : WhenGet
    {
        private Guid _songId = Guid.NewGuid();
        protected override Guid SongId
        {
            get { return _songId; }
        }

        protected override void Arrange()
        {
            base.Arrange();
            SongsInRepository.Add(new Song { Id = SongId });
        }

        [TestMethod]
        public void ThenResultShouldHaveId()
        {
            Assert.IsNotNull(Result);
            Assert.AreEqual(SongId, Result.Id);
        }
    }
}
